package com.spyx.acl.controller;


import com.atyx.spyx.model.acl.Permission;
import com.spyx.acl.service.PermissionService;
import com.spyx.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "菜单管理")
@RestController
//@CrossOrigin
@RequestMapping("admin/acl/permission")
public class PermissionController {
    @Autowired
    private PermissionService permissionService;

    @GetMapping
    @ApiOperation("获取菜单列表")
    public Result getMenus(){
        List<Permission> list = permissionService.queryMenus();
        return Result.ok(list);
    }

    @DeleteMapping("remove/{id}")
    @ApiOperation("删除菜单")
    public Result deleteMenu(@PathVariable("id") Integer id){
        //注意:不能直接调取id删除，因为被删除的菜单id可能包含下一级菜单
        permissionService.deletebyids(id);
        return  Result.ok();
    }
    @PostMapping("save")
    @ApiOperation("保存菜单")
    public Result saveMenu(@RequestBody Permission permission){
        permissionService.save(permission);
        return Result.ok();
    }

    @PutMapping("save")
    @ApiOperation("更新菜单")
    public Result updateMenu(@RequestBody Permission permission){
        permissionService.updateById(permission);
        return Result.ok();
    }
}
